<?php

class App_View_Helper_AjaxPaginator{

	public function AjaxPaginator($function,$param1,$page,$cnt,$limit =10){

		
		$pagination ="";
		$adjacents = 3;

		if($cnt > $limit){
			$totalPages = ceil($cnt/10);
		}else{
			$totalPages = 1;
		}

		if($page%5 == 0){

			$start = $page;
			$end = $page + 4;

		}else{
			$block = floor($page/5);
			$start = ($block*5) + 1;
			$end = $start + 4;

		}
		if($totalPages < $end){
			$end = $totalPages;
		}

		$str = "";


		if($totalPages > 1){

			$pagination .= '<div id="pagination" align="center"><a href="javascript:'.$function.'('.$param1.',1)'.'" class="page-num-first">First</a>&nbsp;';
			if($page != 1){
				$pagination .= '<a href="javascript:'.$function.'($param1,'.($page-1).')'.'" class="page-num-first">Prev</a>';
			}
			for($i = $start; $i<=$end; $i++){
			if($page==$i)
				{
					
					$class = 'pagingCurrent';
                    
				}
			else
				{
					$class = 'paging';
                  
				}
				$pagination.= '<a href="javascript:'.$function.'('.$param1.','.$i.')'.'" class="'.$class.'">'.$i.' </a>';

			}
			if($page < $totalPages){
				$pagination .= '<a href="javascript:'.$function.'($param1,'.($page+1).')'.'" class="page-num-first">Next</a>&nbsp;';
			}

			$pagination .= ' <a href="javascript:'.$function.'($param1,'.$totalPages.')'.'" class="page-num-first">Last</a></div>';
		}
		
		return $pagination;
		

	}
}
?>
